package com.xiaobaibai.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.time.DateUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 
 * </p>
 *
 * @author xiaobaibai
 * @since 2020-11-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("bargain_user")
@ApiModel(value="BargainUser对象", description="")
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class BargainUser implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户砍价表id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "用户id")
    @TableField("user_id")
    private Integer userId;

    @ApiModelProperty(value = "商品id")
    @TableField("product_id")
    private Integer productId;

    @ApiModelProperty(value = "进度单位")
    @TableField("bargain_unit")
    private Integer bargainUnit;

    @ApiModelProperty(value = "新用户的进度单位")
    @TableField("bargain_new_unit")
    private Integer bargainNewUnit;

    @ApiModelProperty(value = "砍价进展(100即成功)")
    @TableField("bargain_progress")
    private Double bargainProgress;

    @ApiModelProperty(value = "状态(正在,失效,成功)")
    @TableField("status")
    private Integer status;

    @ApiModelProperty(value = "失效时间")
    @TableField("failure_time")
    private Date failureTime;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    public static BargainUser convertToBargainUser(BargainProduct bargainProduct,Integer userId){
        BargainUser bargainUser=new BargainUser();
        bargainUser.setProductId(bargainProduct.getProductId());
        bargainUser.setBargainNewUnit(bargainProduct.getBargainNewUnit());
        bargainUser.setBargainUnit(bargainProduct.getBargainUnit());
        bargainUser.setBargainProgress(0D);
        bargainUser.setFailureTime(DateUtils.addDays(new Date(),1));//一天的有效期
        bargainUser.setStatus(0);//正在进行中
        bargainUser.setUserId(userId);
        return bargainUser;
    }

}
